package com.vic.other;

import com.vic.enums.PageSizeEnum;;

/**
 * @Author: Vic Ly
 */
public class SimplePage {
    private int pageNum; //当前页
    private int countTotal;// 总记录数
    private int pageSize;// 每页记录数
    private int pageTotal;// 总页数
    private int start; //起始页
    private int end;//截止页

    public SimplePage() {
    }

    public SimplePage(Integer pageNum, int countTotal, int pageSize) {
        if( null == pageNum) pageNum =0;
        this.pageNum = pageNum;
        this.countTotal = countTotal;
        this.pageSize = pageSize;
        action();
    }

    public SimplePage(int start, int end) {
        this.start = start;
        this.end = end;
    }

    // 分页方法
    public void action(){
        if(this.pageSize <= 0){
            this.pageSize = PageSizeEnum.SIZE20.getSize();
        }
        if(this.countTotal > 0){
            this.pageTotal = this.countTotal % this.pageSize == 0 ?this.countTotal / this.pageSize
                    : this.countTotal / this.pageSize + 1;
        }else {
            pageTotal = 1;
        }
        if(pageNum <=1){
            pageNum = 1;
        }
        if(pageNum > pageTotal){
            pageNum = pageTotal;
        }
        this.start = (pageNum  - 1) * pageSize;
        this.end = this.pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getCountTotal() {
        return countTotal;
    }

    public void setCountTotal(int countTotal) {
        this.countTotal = countTotal;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageTotal() {
        return pageTotal;
    }

    public void setPageTotal(int pageTotal) {
        this.pageTotal = pageTotal;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }
}
